<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <h:form id="frmOrganization">
        <p:growl id="messageGeneral" showDetail="true" sticky="false" />
        <p:dataTable id="organizationTable" var="orgItem" 
                     value="#{mbVOrganization.all}" 
                     paginator="true" rows="15" paginatorPosition="bottom"
                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} 
                                        {PreviousPageLink} {PageLinks} 
                                        {NextPageLink} {LastPageLink}"
                     emptyMessage="Нет организаций">
            <f:facet name="header">
                Список организаций                            
            </f:facet>
            <p:column width="300" headerText="Организация">
                <h:outputText value="#{orgItem.name}" />
            </p:column>
            <p:column width="100">
                <p:commandButton icon="ui-icon-disk" 
                                 action="#{mbVOrganization.setOrganizationParent()}"
                                 oncomplete="dialogOrganization.hide()"
                                 style="float:right;width:32px;height:32px;">
                    <f:setPropertyActionListener value="#{orgItem}"
                                                 target="#{mbVOrganization.organization}" />
                </p:commandButton>
                <p:commandButton icon="ui-icon-trash"
                                 oncomplete="deleteOganizationDlg.show()"
                                 style="float:right;width:32px;height:32px;">
                    <f:setPropertyActionListener value="#{orgItem}"
                                                 target="#{mbVOrganization.organization}" />
                </p:commandButton>
                <p:commandButton update=":frmOrganization:editOrganizationDialog" 
                                 icon="ui-icon-pencil"
                                 oncomplete="editOrganizationDlg.show()"
                                 style="float:right;width:32px;height:32px;">
                    <f:setPropertyActionListener value="#{orgItem}"
                                                 target="#{mbVOrganization.organization}" />
                </p:commandButton>                
            </p:column>
        </p:dataTable>
        <h:panelGroup layout="block" style="text-align: right">
            <p:commandButton value="Новая организация" 
                             oncomplete="newOrganizationDlg.show()" />
        </h:panelGroup>

        <!--    Add new organization -dialog -->
        <p:dialog widgetVar="newOrganizationDlg" id="newOrganizationDialog"
                  header="Новая организация" hideEffect="fade"
                  showEffect="fade" resizable="false" closable="true">

            <h:panelGrid columns="3" >
                <h:outputText value="Короткое наименование" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.name}"
                             maxlength="128" />
                <h:outputText value="Полное наименование" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.fullName}"
                             maxlength="128" />
                <h:outputText value="Телефон" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.phone}"
                             maxlength="128" />
                <h:outputText value="Эл. почта" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.email}"
                             maxlength="128" />
                <p:outputLabel value="Адрес" for="txtAddress"/>
                <p:spacer width="10" height="10" />
                <h:panelGroup>
                    <p:inputText id="txtAddress" 
                                 label="Адрес"
                                 value="#{mbVOrganization.organization.address.addrFias}"
                                 readonly="true">
                    </p:inputText>   
                    <p:spacer width="10" height="10" />
                    <p:commandButton value="..." styleClass="button"
                                     action="#{mbVOrganization.setAddressOrganization()}"
                                     process="@this" />
                </h:panelGroup>
                <h:outputText value="ОГРН" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.ogrn}"
                             maxlength="128" />
                <h:outputText value="ИНН" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.inn}"
                             maxlength="128" />
                <h:outputText value="КПП" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.kpp}"
                             maxlength="128" />
                <h:outputText value="Рсчетный счет" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.rsch}"
                             maxlength="128" />
                <h:outputText value="Корреспонденский счет" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.ksch}"
                             maxlength="128" />
                <h:outputText value="Банк" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.bank}"
                             maxlength="128" />
                <h:outputText value="БИК Банка" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.bik}"
                             maxlength="128" />
                <h:outputText value="ОКПО" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.newOrganization.okpo}"
                             maxlength="128" />
                <h:outputText value="Упращенный учет" />
                <p:spacer width="10" height="10" />
                <p:selectBooleanCheckbox value="#{mbVOrganization.newOrganization.nds}" />
                <h:outputText value="Дата регистрации" />
                <p:spacer width="10" height="10" />
                <p:calendar id="button1" value="#{mbVOrganization.newOrganization.regDate}" showOn="button" />
            </h:panelGrid>
            <h:panelGroup layout="block" style="text-align: right">
                <p:commandButton value="Сохранить" action="#{mbVOrganization.registration()}"
                                 oncomplete="newOrganizationDlg.hide();" update="organizationTable">
                </p:commandButton>
                <p:commandButton value="Отменить" oncomplete="newOrganizationDlg.hide();"
                                 action="#{mbVOrganization.cancel()}" />
            </h:panelGroup>

        </p:dialog>

        <!--    Delete organization -dialog -->
        <p:dialog widgetVar="deleteOganizationDlg" id="deleteOrganzationDialog"
                  header="Удаление организаци" hideEffect="fade"
                  showEffect="fade" resizable="false" 
                  closable="true">

            <h:outputText value="Удаляем оганизацию?" />

            <h:panelGroup layout="block" style="text-align: right">
                <p:commandButton value="Удалить" action="#{mbVOrganization.remove()}"
                                 oncomplete="deleteOganizationDlg.hide();" update="organizationTable">
                </p:commandButton>
                <p:commandButton value="Отменить"
                                 oncomplete="deleteOganizationDlg.hide();"
                                 action="#{mbVOrganization.cancel()}" />
            </h:panelGroup>

        </p:dialog>

        <!--    Editing organization -dialog -->
        <p:dialog widgetVar="editOrganizationDlg" id="editOrganizationDialog"
                  header="Редактирование организации" hideEffect="fade"
                  showEffect="fade" resizable="false" closable="true"
                  width="600">

            <h:panelGrid columns="3">
                <h:outputText value="Имя" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.name}"
                             maxlength="128" />
                <h:outputText value="Полное наименование" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.fullName}"
                             maxlength="128" />
                <h:outputText value="Телефон" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.phone}"
                             maxlength="128" />
                <h:outputText value="Эл. почта" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.email}"
                             maxlength="128" />
                <h:outputText value="Адрес" />
                <p:spacer width="10" height="10" />
                <h:panelGroup>
                    <p:inputText id="txtAddressUpdate" 
                                 label="Адрес"
                                 value="#{mbVOrganization.organization.address.addrFias}"
                                 readonly="true">
                    </p:inputText>     
                    <p:commandButton value="..." styleClass="button"
                                     action="#{mbVOrganization.setAddressOrganization()}"
                                     process="@this" />
                </h:panelGroup>
                <h:outputText value="ОГРН" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.ogrn}"
                             maxlength="128" />
                <h:outputText value="ИНН" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.inn}"
                             maxlength="128" />
                <h:outputText value="КПП" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.kpp}"
                             maxlength="128" />
                <h:outputText value="Рсчетный счет" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.rsch}"
                             maxlength="128" />
                <h:outputText value="Корреспонденский счет" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.ksch}"
                             maxlength="128" />
                <h:outputText value="Банк" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.bank}"
                             maxlength="128" />
                <h:outputText value="БИК Банка" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.bik}"
                             maxlength="128" />
                <h:outputText value="ОКПО" />
                <p:spacer width="10" height="10" />
                <p:inputText value="#{mbVOrganization.organization.okpo}"
                             maxlength="128" />
                <h:outputText value="Упращенный учет" />
                <p:spacer width="10" height="10" />
                <p:selectBooleanCheckbox value="#{mbVOrganization.organization.nds}" />
                <h:outputText value="Дата регистрации" />
                <p:spacer width="10" height="10" />
                <p:calendar id="button2" value="#{mbVOrganization.organization.regDate}" showOn="button" />
            </h:panelGrid>
            <h:panelGroup layout="block" style="text-align: right">
                <p:commandButton value="Сохранить" action="#{mbVOrganization.update()}"
                                 oncomplete="editOrganizationDlg.hide();" update="organizationTable">
                </p:commandButton>
                <p:commandButton value="Отменить" oncomplete="editOrganizationDlg.hide();"
                                 action="#{mbVOrganization.cancel()}" />
            </h:panelGroup>
        </p:dialog>
        
        <!--    Address organization Dialog   -->
        <p:dialog widgetVar="dialogAddress" id="OrganizationDialogAddress"
                  header="Редактирование организации" hideEffect="fade"
                  showEffect="fade" resizable="false" closable="true">
            <ui:include src="/fias/address.xhtml"/>
            <p:ajax event="close" update=":frmOrganization:txtAddress txtAddressUpdate" />
        </p:dialog>
    </h:form>
</html>

